package com.gek.yudada.mapstruct.quenstion;

import cn.hutool.json.JSONUtil;
import com.gek.yudada.model.dto.question.QuestionDTORequest;
import com.gek.yudada.model.entity.Question;
import com.gek.yudada.model.vo.QuestionVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface QuestionConvert {
    QuestionConvert INSTANCE = Mappers.getMapper(QuestionConvert.class);

    @Mapping(source = "questionContent",target = "questionContent",qualifiedByName = "StringToList")
    QuestionVO objToVo(Question question);



    @Named("StringToList")
    default List<QuestionDTORequest> StringToList(String questionContent) {
        if(questionContent== null){
            return null;
        }
        List<QuestionDTORequest> questionDTORequest = JSONUtil.toList(questionContent, QuestionDTORequest.class);
        return questionDTORequest;
    }
}
